package com.alks.function.controller.biocontrol.webWork;


import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.WebLogger;
import com.alks.common.utils.beanutils.ArrayUtils;
import com.alks.entity.data.entity.PsScheduleHeadCut;
import com.alks.entity.data.page.PageRecord;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.entity.exception.InDataException;
import com.alks.entity.exception.ServiceErrorException;
import com.alks.function.data.dto.biocontrol.webwork.SchLineDto;
import com.alks.function.data.request.biocontrol.webwork.ScheduleCutLotRequest;
import com.alks.function.service.biocontrol.deptwork.IScheduleCutLotService;
import com.alks.function.service.common.BackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@ApiRestController("/schedule/cut")
@Api(value = "生控部", tags = {"生控部-web查询-冲裁进度-待安排指令明细", "生控部-web查询-冲裁进度"})
@Slf4j
public class ScheduleCutController {
    @Autowired
    private IScheduleCutLotService scheduleCutLotService;
    @Autowired
    private BackService backService;

    @WebLogger
    @PostMapping("/un/list")
    @ApiOperation(value = "待安排指令明细查询", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo unList(@RequestBody ScheduleCutLotRequest scheduleCutLot) {
        return scheduleCutLotService.getUnScheduleList(scheduleCutLot);
    }

    @WebLogger
    @GetMapping("/line")
    @ApiOperation(value = "生产线查询", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo line() {
        List<SchLineDto> dtoList = scheduleCutLotService.line();
        return ResponseInfo.ok(dtoList);
    }

    @WebLogger
    @PostMapping("/detail/list")
    @ApiOperation(value = "已排进度明细", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo detailList(@RequestBody ScheduleCutLotRequest request) {
        PageRecord<PsScheduleHeadCut> record = scheduleCutLotService.detailList(request);
        return ResponseInfo.ok(record);
    }

    @WebLogger
    @PostMapping("/sch")
    @ApiOperation(value = "整单安排", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo sch(@RequestBody List<String> lotNoList,
                            @RequestParam String line,
                            @RequestParam BigDecimal seqNo) {
        if (ArrayUtils.isEmpyt(lotNoList)) {
            throw new InDataException("指令不能为空");
        }
        backService.getRyLotCheck(lotNoList);
        scheduleCutLotService.sch(lotNoList, line, seqNo);
        return ResponseInfo.ok();
    }

    @WebLogger
    @PutMapping("/sch/cancel")
    @ApiOperation(value = "取消安排", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo cancelSch(@RequestParam String line,
                                  @RequestParam String seqNo) {
        scheduleCutLotService.cancelSch(line, seqNo);
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/up")
    @ApiOperation(value = "更新指令", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo tempUp() {
        scheduleCutLotService.tempUp();
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/sch/up")
    @ApiOperation(value = "更新进度表", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo schUp() {
        scheduleCutLotService.schUp();
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/sch/ud")
    @ApiOperation(value = "上移下移", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo schUd(@RequestParam String line,
                              @RequestParam List<BigDecimal> seqNoList,
                              @RequestParam Integer type) {
        scheduleCutLotService.schUd(line, seqNoList, type);
        return ResponseInfo.ok();
    }

    @WebLogger
    @GetMapping("/sch/moveLine")
    @ApiOperation(value = "调整进度", tags = "生控部-web查询-冲裁进度")
    public ResponseInfo schMoveLine(@RequestParam String line,
                                    @RequestParam List<BigDecimal> seqNoList,
                                    @RequestParam String tagLine) {
        scheduleCutLotService.schMoveLine(line, seqNoList, tagLine);
        return ResponseInfo.ok();
    }


}